package week1.undirected;

import edu.princeton.cs.introcs.In;
import edu.princeton.cs.introcs.StdOut;
import graph.impl.StringGraph;
import graph.impl.StringGraphDFS;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class UnDirectedGraphDFS {
	private Map<String,Boolean> visited = null;
	private StringGraph graph = null;

	public UnDirectedGraphDFS(StringGraph graph, String sourceVertex) {
		this.graph = graph;
		visited = new HashMap<String, Boolean>();
		dfs(sourceVertex);
	}
	public void dfs(String sourceVertex){
		Set<String> edges = graph.getEdges(sourceVertex);
		this.visited.put(sourceVertex, Boolean.TRUE);
		System.out.print(sourceVertex +" ");
		for(String edge : edges){
			if(visited.get(edge) == null){
				dfs(edge);
			}
		}
	}
	public static void main(String[] args) {
		In in = new In(args[0]);
		StringGraph stringGraph = new StringGraph(in);
		UnDirectedGraphDFS dfs = new UnDirectedGraphDFS(stringGraph,"A");
//		if(dfs.visited.size() == stringGraph.vertexCount) {
//			StdOut.println(dfs.visited);
//		}
	}

}
